import os
from config.dev_config import LOG_CONFIG as DEV_CONFIG
from config.prod_config import LOG_CONFIG as PROD_CONFIG
from datetime import datetime

# 默认配置
DEFAULT_CONFIG = {
    'LOG_DIR': 'logs',
    'LOG_FORMAT': "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
    'DATE_FORMAT': "%Y-%m-%d %H:%M:%S",
    'LOG_LEVEL': 'INFO',
    'LOG_FILE_MAX_BYTES': 10 * 1024 * 1024,
    'LOG_FILE_BACKUP_COUNT': 5,
    'LOG_FILE_ENCODING': 'utf-8'
}

def get_config():
    """根据环境变量获取对应的配置"""
    env = os.getenv('ENV', 'dev').lower()
    
    if env == 'prod':
        config = PROD_CONFIG
    elif env == 'dev':
        config = DEV_CONFIG
    else:
        config = DEFAULT_CONFIG
    
    return config

def get_log_file():
    """获取日志文件路径"""
    config = get_config()
    current_date = datetime.now().strftime("%Y-%m-%d")
    return os.path.join(config['LOG_DIR'], f"app_{current_date}.log")

# 导出当前环境的配置
LOG_CONFIG = get_config() 